package com.hsytech.dijiebao.person.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hsytech.dijiebao.R;
import com.hsytech.dijiebao.base.BaseActivity;
import com.hsytech.dijiebao.base.DialogFragmentListener;
import com.hsytech.dijiebao.base.SimpleDialogFrament;
import com.hsytech.dijiebao.home.alldetail.HotelDetailActivity;
import com.hsytech.dijiebao.home.alldetail.MyselfHotelDetailActivity;
import com.hsytech.dijiebao.home.alldetail.MyselfTaxiDetailActivity;
import com.hsytech.dijiebao.home.alldetail.TaxiDetailActivity;
import com.hsytech.dijiebao.person.InformationAdapter;
import com.hsytech.dijiebao.person.dao.InformationDao;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

public class InformitionActivity extends BaseActivity {
	private ListView informition_list;
	private TextView bar_title_tv, default_text;
	private InformationAdapter taxiAdapter;
	private List<HashMap<String, String>> listdatat = new ArrayList<HashMap<String, String>>();
	private ImageButton top_back_btn;
	private Button bar_right_top_btn;
	private List<Map<String, Object>> daoList = new ArrayList<Map<String, Object>>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.information);
		initView();
	}

	private void initView() {
		initTitle();
		initBody();
	}

	private void initBody() {

		informition_list = (ListView) findViewById(R.id.informition_list);
		taxiAdapter = new InformationAdapter(this, listdatat);
		informition_list.setAdapter(taxiAdapter);

		daoList = InformationDao.informationDao.queryAll();
		if (daoList != null) {
			for (int i = 0; i < daoList.size(); i++) {
				HashMap<String, String> taxiList = new HashMap<String, String>();
				// taxiList = listdatat.get(i);
				taxiList.put("content", (String) daoList.get(i).get("content"));

				listdatat.add(taxiList);
				//
			}
			taxiAdapter.notifyDataSetChanged();
		}
		informition_list.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {

				Log.d("mylog", "�б�id" + (String) daoList.get(position).get("id"));
				DialogFragmentListener listener = new DialogFragmentListener() {
					@Override
					public void onPositive() {
						InformationDao.informationDao.delID((String) daoList.get(position).get("id"));
						listdatat.remove(position);
						taxiAdapter.notifyDataSetChanged();
					}

					@Override
					public void onNegative() {

					}
				};
				SimpleDialogFrament.with(InformitionActivity.this).message("ȷ��ɾ����?").attach(listener).showDialog();

				return true;
			}
		});

		informition_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				if (daoList.get(position).get("carorhotle").equals("1")
						&& daoList.get(position).get("status").equals("1")) {

					Intent TaxiDetail = new Intent(InformitionActivity.this, TaxiDetailActivity.class);
					TaxiDetail.putExtra("idTaxiHelp", (String) daoList.get(position).get("id"));
					TaxiDetail.putExtra("collectTaxi", "1");
					// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					startActivity(TaxiDetail);
				}

				// ���г���
				if (daoList.get(position).get("carorhotle").equals("1")
						&& daoList.get(position).get("status").equals("2")) {

					Intent MyselfTaxiDetail = new Intent(InformitionActivity.this, MyselfTaxiDetailActivity.class);
					MyselfTaxiDetail.putExtra("idTaxi", (String) daoList.get(position).get("id"));
					MyselfTaxiDetail.putExtra("collectMyTaxi", "1");
					// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					startActivity(MyselfTaxiDetail);
				}
				// �����Ƶ�
				if (daoList.get(position).get("carorhotle").equals("2")
						&& daoList.get(position).get("status").equals("1")) {
					Intent HotelDetail = new Intent(InformitionActivity.this, HotelDetailActivity.class);
					HotelDetail.putExtra("idHelp", (String) daoList.get(position).get("id"));
					HotelDetail.putExtra("collectHotle", "1");
					// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					startActivity(HotelDetail);
				}
				// ����Ƶ�
				if (daoList.get(position).get("carorhotle").equals("2")
						&& daoList.get(position).get("status").equals("2")) {
					Intent MyselfHotelDetail = new Intent(InformitionActivity.this, MyselfHotelDetailActivity.class);
					MyselfHotelDetail.putExtra("id", (String) daoList.get(position).get("id"));
					MyselfHotelDetail.putExtra("collectMyHotle", "1");
					// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					startActivity(MyselfHotelDetail);
				}
			}
		});
		// informition_list.setOnRefreshListener(new
		// PullToRefreshBase.OnRefreshListener2<ListView>() {
		// @Override
		// public void onPullDownToRefresh(PullToRefreshBase<ListView>
		// refreshView) {
		// listdatat.clear();
		// taxiAdapter.notifyDataSetChanged();
		// }
		//
		// @Override
		// public void onPullUpToRefresh(PullToRefreshBase<ListView>
		// refreshView) {
		// // if (currentNum == 0) {
		// // listview_more_taxi.onRefreshComplete();
		// // return;
		// // }
		// // if (currentNum >= Integer.valueOf(count)) {
		// // // Toast.makeText(getActivity(), "û�и���������",
		// // // Toast.LENGTH_SHORT).show();
		// //
		// // new Handler().postDelayed(new Runnable() {
		// //
		// // @Override
		// // public void run() {
		// // listview_more_taxi.onRefreshComplete();
		// //
		// // }
		// // }, 500);
		// // }
		// // firstRow = firstRow + listRows;
		// // getHttp();
		// }
		// });
	}

	private void initTitle() {
		top_back_btn = (ImageButton) findViewById(R.id.top_back_btn);
		top_back_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		bar_right_top_btn = (Button) findViewById(R.id.bar_right_top_btn);
		bar_right_top_btn.setVisibility(View.GONE);
		bar_title_tv = (TextView) findViewById(R.id.bar_title_tv);
		bar_title_tv.setText("ϵͳ��Ϣ");
	}

}
